package xyz.lne.researchgroupmanage.mapper.neo4j;

import org.neo4j.ogm.model.Result;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.stereotype.Repository;
import xyz.lne.researchgroupmanage.entity.neo4j.ResearchNode;

@Repository
public interface ResearchNodeRepository extends Neo4jRepository<ResearchNode, Long> {

    @Query("MATCH (r:research{researchId:$researchId}) RETURN r")
    ResearchNode findResearchNodeByRId(Integer researchId);

    @Query("MATCH (p1:research {researchId: $researchId})-[:kr]->(cuisine1) WITH p1, collect(id(cuisine1)) AS p1Cuisine MATCH (relatedResearch:research)-[:kr]->(cuisine2) WHERE p1 <> relatedResearch WITH p1, p1Cuisine,relatedResearch, collect(id(cuisine2)) AS relatedResearchCuisine RETURN relatedResearch, gds.alpha.similarity.jaccard(p1Cuisine, relatedResearchCuisine) AS similarity  ORDER BY similarity  DESC  LIMIT $size")
    Result findRelatedResearchByRId(Integer researchId, Integer size);
}
